const http = require("http");
const querystring = require("querystring");
const server = http.createServer();

const msgList = []

server.on("request", function (req, res) {
  const method = req.method;
  if (method === "POST") {
    
    let body = "";
    req.on("data", (chunk) => {
        body += chunk.toString();
    });
 
    req.on("end", () => {
        body = JSON.parse(body)
        const data = body.data
        console.log('消息',data)
        msgList.push(...data) 
        res.writeHead(200, {
            "content-type": "application/json;charset=utf-8",
          });
          setTimeout(() => {
            res.end(JSON.stringify(msgList.length));
          }, 10000)
        
    })
  }
});

server.listen(3030, function () {
  console.log("服务器运行中 地址 http://127.0.0.1:3030");
});
